﻿#include "CmdSaveGraph.h"
#include <QFile>
#include <QDebug>
#include "BaseModule/IBaseSignal.h"
#include "PostCommandPy.h"

namespace PostCommand
{
    CmdSaveGraph::CmdSaveGraph()
        : CommandBase()
    {
        this->initCmdName();
    }
    CmdSaveGraph::~CmdSaveGraph()
    {
    }

    bool CmdSaveGraph::execute()
    {
        bool _success = false;
        if (!m_filePath.isEmpty())
        {
            emit IBaseSignalInstance->signal_saveGraph(m_filePath, &_success);
        }
        else
        {
            qDebug() << "CmdSaveGraph::execute() filePath is empty!";
        }
        if (!_success)
        {
            emit IBaseSignalInstance->signal_UpdateStatusBarInformation(QString("保存图片失败！"), false);
            emit IBaseSignalInstance->signal_sendErrorMessageToUI("保存图片失败: " + m_filePath);
        }
        else
            emit IBaseSignalInstance->signal_UpdateStatusBarInformation(QString("保存图片成功！"), false);
        return _success;
    }

    void CmdSaveGraph::undo()
    {
        QFile::remove(m_filePath);
    }

    void CmdSaveGraph::redo()
    {
        execute();
    }

    void CmdSaveGraph::setFilePath(QString filePath)
    {
        m_filePath = filePath;
    }

}
